using Assets.Scripts.GDK;
using DG.Tweening;
using SimpleJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class GameDebug : gdk_base_panel
	{
		public RectTransform boxContent;

		public RectTransform infoContent;

		public override void OnLoad()
		{
			gdk_utils.removeAllChildren(boxContent);
			gdk_utils.removeAllChildren(infoContent);
		}

		public override void OnStart()
		{
			Dictionary<string, Action> onGameDebugDelegate = new Dictionary<string, Action>();
			onGameDebugDelegate.Add("重置", czfunc);
			onGameDebugDelegate.Add("下一关", xygfunc);
			onGameDebugDelegate.Add("上一关", sygfunc);
			onGameDebugDelegate.Add("全通关", endfunc);
			onGameDebugDelegate.Add("加金币", jjbfunc);
			onGameDebugDelegate.Add("加积分", jjffunc);
			onGameDebugDelegate.Add("ad_banner", ad1func);
			onGameDebugDelegate.Add("ad_插屏", ad2func);
			onGameDebugDelegate.Add("ad_全屏", ad3func);
			onGameDebugDelegate.Add("ad_激励", ad4func);
			onGameDebugDelegate.Add("ad_原生", ad5func);
			onGameDebugDelegate.Add("ad_原生Icon", ad6func);
			onGameDebugDelegate.Add("ad_原生json", ad7func);
			onGameDebugDelegate.Add("ad_插屏2", ad8func);
			onGameDebugDelegate.Add("ad_聚合", ad9func);
			onGameDebugDelegate.Add("动画", anifunc);
			onGameDebugDelegate.Add("关广告", closeADfunc);
			onGameDebugDelegate.Add("开广告", openADfunc);
			onGameDebugDelegate.Add("奖励", addCoinAlertfunc);
			onGameDebugDelegate.Add("加技能卡", addCardsfunc);
			onGameDebugDelegate.Add("禁用btn", setButtonOnEnabled);
			onGameDebugDelegate.Add("启用btn", setButtonOffEnabled);
			onGameDebugDelegate.Add("LOG", showLogFun);
			onGameDebugDelegate.Add("Shape", GetScreenShapeFun);
			onGameDebugDelegate.Add("Shape2", GetScreenShapeFun2);
			onGameDebugDelegate.Add("显示每日奖励", showWelcomeFun);
			onGameDebugDelegate.Add("显示每日奖励alert", showWelcomeFun2);
			onGameDebugDelegate.Add("新手引导1", skillDisplayFun1);
			onGameDebugDelegate.Add("新手引导2", skillDisplayFun2);
			onGameDebugDelegate.Add("新手引导3", skillDisplayFun3);
			onGameDebugDelegate.Add("新手引导4", skillDisplayFun4);
			onGameDebugDelegate.Add("新手引导5", skillDisplayFun5);
			onGameDebugDelegate.Add("新手引导6", skillDisplayFun6);
			onGameDebugDelegate.Add("新手引导7", skillDisplayFun7);
			onGameDebugDelegate.Add("加载释义", loadWordInfoJsonFun);
			onGameDebugDelegate.Add("能否播放广告", isAdSwitchPlayFun);
			onGameDebugDelegate.Add("关卡过关信息", GetAdSwitchOdds);
			onGameDebugDelegate.Add("修改速度", changeSpeed);
			foreach (string key in onGameDebugDelegate.Keys)
			{
				GameObject gameObject = gdk_game_manager.loadPrefab(ItemID.GameDebugItemPrefab);
				Transform transform = gdk_utils.FindChild(gameObject.transform, "textStr");
				Text component = transform.GetComponent<Text>();
				component.text = key;
				component.fontSize = 22;
				gameObject.transform.SetParent(boxContent, worldPositionStays: false);
				Button button = transform.gameObject.AddComponent<Button>();
				button.onClick.AddListener(delegate
				{
					gdk_game_manager.PlaySound(AudioID.click);
					onGameDebugDelegate[key]();
				});
			}
		}

		public void czfunc()
		{
			GameData.index = 1;
			GameData.coin = 0;
			GameData.stars = 0;
			GameData.selectIndex = 1;
			GameData.dayFirstLogin = 0;
			GameData.levelNote = string.Empty;
			GameData.dailyRecod = string.Empty;
			GameData.pifuballs = string.Empty;
			gdk_game_manager.log("重置");
			gdk_game_manager.loadScene(SceneID.START);
			GameData.buyNewerGift = false;
			GameData.buyWeekGift = false;
			GameData.dayLookAd = 0;
			GameData.closeAD = false;
		}

		public void xygfunc()
		{
			GameData.index++;
			gdk_game_manager.log("当前关卡" + GameData.index);
		}

		public void sygfunc()
		{
			if (GameData.index > 0)
			{
				GameData.index--;
				gdk_game_manager.log("当前关卡" + GameData.index);
			}
			else
			{
				gdk_game_manager.log("第一关了");
			}
		}

		public void endfunc()
		{
			GameData.index = 150;
		}

		public void jjbfunc()
		{
			GameManager.addCoin(1000);
			gdk_game_manager.log("金币+1000");
		}

		public void jjffunc()
		{
			GameManager.addStar(1000);
			gdk_game_manager.log("积分+1000");
		}

		public void xsjsunc()
		{
			gdk_game_manager.showPanel(PanelID.COMPLETE_INFO);
			close();
		}

		public void ad1func()
		{
			adfunc("1");
		}

		public void ad2func()
		{
			adfunc("2");
		}

		public void ad3func()
		{
			adfunc("3");
		}

		public void ad4func()
		{
			adfunc("4");
		}

		public void ad5func()
		{
			adfunc("5");
		}

		public void ad6func()
		{
			adfunc("6");
		}

		public void ad7func()
		{
			adfunc("7");
		}

		public void ad8func()
		{
			adfunc("8");
		}

		public void ad9func()
		{
			adfunc("9");
		}

		public void adfunc(string adTpye)
		{
			JsonObject jsonObject = new JsonObject();
			AdSize value = new AdSize();
			jsonObject.Add("rect", value);
			jsonObject.Add("fitMode", 1);
			jsonObject.Add("designWidth", 720);
			jsonObject.Add("designHeight", 1280);
			jsonObject.Add("realWidth", 720);
			jsonObject.Add("realHeight", 1280);
			jsonObject.Add("extra", new JsonObject());
			string extrainfo = SimpleJson.SimpleJson.SerializeObject(jsonObject);
			GameManager.PlayAdvert("10001", adTpye, delegate
			{
				gdk_game_manager.log("视频完成");
				int num = gdk_utils.Random(51, 100);
				GameManager.showAddCoinAlert(num, 2);
				GameManager.addCoin(num);
			}, delegate
			{
				gdk_game_manager.log("广告遇到其它类型错误失败");
			}, delegate
			{
				gdk_game_manager.log("视频取消");
			}, extrainfo);
			close();
		}

		public void anifunc()
		{
			close();
			Action<Ease, RectTransform, Action> actionFun = delegate (Ease type, RectTransform rt, Action actionCallback)
			{
				Text component = gdk_utils.FindChild(rt, "Text").GetComponent<Text>();
				component.fontSize = 30;
				rt.localScale = new Vector3(0f, 0f, 0f);
				rt.DOScale(1f, 0.8f).SetEase(type).OnComplete(delegate
				{
					actionCallback();
				});
				component.text = type.ToString();
			};
			GameObject gameObject = GameObject.Find("Canvas");
			Image image = gdk_utils.NewImage();
			Text text = gdk_utils.NewText();
			RectTransform imgRT = image.GetComponent<RectTransform>();
			imgRT.sizeDelta = new Vector2(350f, 350f);
			imgRT.SetParent(gameObject.transform);
			text.transform.SetParent(imgRT);
			List<gdk_coroutineAnimatorStruct> list = new List<gdk_coroutineAnimatorStruct>();
			IEnumerator enumerator = Enum.GetValues(typeof(Ease)).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Ease item = (Ease)enumerator.Current;
					list.Add(new gdk_coroutineAnimatorStruct
					{
						gameObject = imgRT.gameObject,
						action = delegate (Action actionCallback)
						{
							actionFun(item, imgRT, actionCallback);
						},
						await = 2.5f
					});
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
			gdk_coroutineAnimators.playAnimators(list, delegate
			{
				UnityEngine.Object.Destroy(imgRT.gameObject, 2f);
			});
		}

		private void closeADfunc()
		{
			GameData.closeAD = true;
			gdk_game_manager.message("关闭广告");
			close();
		}

		private void openADfunc()
		{
			GameData.closeAD = false;
			gdk_game_manager.message("开启广告");
			close();
		}

		private void addCoinAlertfunc()
		{
			GameManager.showAddCoinAlert(gdk_utils.Random(100, 1000), 2);
			close();
		}

		private void addCardsfunc()
		{
		}

		private void setButtonOnEnabled()
		{
			gdk_game_manager.setButtonEnabled(isEnabled: false);
			close();
		}

		private void setButtonOffEnabled()
		{
			gdk_game_manager.setButtonEnabled(isEnabled: true);
			close();
		}

		private void showLogFun()
		{
			gdk_debugConsole instance = gdk_debugConsole.Instance;
			if ((bool)instance)
			{
				instance.Show();
			}
		}

		private void GetScreenShapeFun()
		{
			//gdk_game_manager.log("hexString type = " + (GameManager.isLiuHaiShape = SDKManager.GetScreenShape(string.Empty)), 20f);
		}

		private void GetScreenShapeFun2()
		{
			//gdk_game_manager.log("hexString type = " + (GameManager.isLiuHaiShape = SDKManager.GetScreenShape("17")), 20f);
		}

		private void showWelcomeFun()
		{
			close();
		}

		private void showWelcomeFun2()
		{
			WelcomeConfigItemModel config = new WelcomeConfigItemModel();
			config.ID = 104;
			config.num = 1;
			config.range = "0.3";
			config.other = "25,25";
			gdk_game_manager.showAlert(AlertID.WELCOME_REWARD_ALERT, delegate (GameObject obj)
			{
				WelcomeRewardAlert component = obj.GetComponent<WelcomeRewardAlert>();
				component.OnData(1, config);
			});
			close();
		}

		private void skillDisplayFun1()
		{
			gdk_game_manager.showGuide(GuideID.SELECT);
			close();
		}

		private void skillDisplayFun2()
		{
			gdk_game_manager.showGuide(GuideID.SHUFFLE);
			close();
		}

		private void skillDisplayFun3()
		{
			gdk_game_manager.showGuide(GuideID.COIN_BONUS);
			close();
		}

		private void skillDisplayFun4()
		{
			gdk_game_manager.showGuide(GuideID.ADD_BONUS);
			close();
		}

		private void skillDisplayFun5()
		{
			gdk_game_manager.showGuide(GuideID.SKILL_TWO);
			close();
		}

		private void skillDisplayFun6()
		{
			gdk_game_manager.showGuide(GuideID.SKILL_THREE);
			close();
		}

		private void skillDisplayFun7()
		{
			gdk_game_manager.showGuide(GuideID.ALERT);
			close();
		}

		private void loadWordInfoJsonFun()
		{
			GameManager.getWordInfoItem("ADS", delegate
			{
			});
			close();
		}

		private void isAdSwitchPlayFun()
		{
			float indexAdSwitchOdds = GameManager.getIndexAdSwitchOdds(GameData.selectIndex);
			bool flag = (float)gdk_utils.Random(0, 100) < 100f * indexAdSwitchOdds;
		}

		private void GetAdSwitchOdds()
		{
			int selectIndex = GameData.selectIndex;
			//int count = SDKManager.AdSwitchList.Count;
			int num = 150;
			float indexAdSwitchOdds = GameManager.getIndexAdSwitchOdds(selectIndex);
			bool flag = (float)gdk_utils.Random(0, 100) < 100f * indexAdSwitchOdds;
			gdk_game_manager.log("关卡index:" + selectIndex + " 总关卡:" + num + " 视频概率:" + indexAdSwitchOdds + " 随机播放视频:" + flag + " 开关配置数:", 5f);
		}

		private void changeSpeed()
		{
			GDK.ModuleManger.Module<BallBoxModule>().AddTestType();
			gdk_game_manager.showPanel(PanelID.TESTSPPED);
			close();
		}
	}
}

